package com.atguigu.controller;

import com.atguigu.model.process.ProcessTemplate;
import com.atguigu.model.process.ProcessType;
import com.atguigu.result.Result;
import com.atguigu.service.OaProcessService;
import com.atguigu.service.OaProcessTemplateService;
import com.atguigu.service.OaProcessTypeService;
import com.atguigu.vo.process.ApprovalVo;
import com.atguigu.vo.process.ProcessFormVo;
import com.atguigu.vo.process.ProcessVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/process")
@CrossOrigin
public class OaProcessApiController {
    @Autowired
    private OaProcessTypeService oaProcessTypeService;
    @Autowired
    private OaProcessTemplateService oaProcessTemplateService;
    @Autowired
    private OaProcessService oaProcessService;
    @GetMapping("findProcessType")
    public Result findProcessType(){
       List<ProcessType> list= oaProcessTypeService.findProcessType();
       return Result.ok(list);
    }
    @GetMapping("getProcessTemplate/{processTemplateId}")
    public Result getProcessTemplate(@PathVariable Long processTemplateId){
        ProcessTemplate processTemplate = oaProcessTemplateService.getById(processTemplateId);
        return Result.ok(processTemplate);
    }
    @PostMapping("startUp")
    public Result startUp(@RequestBody ProcessFormVo processFormVo){
        oaProcessService.startUp(processFormVo);
        return Result.ok();
    }
    @GetMapping("findPending/{page}/{limit}")
    public Result findPending(@PathVariable Integer page,@PathVariable Integer limit){
        IPage<ProcessVo> pageParam=new Page<>(page,limit);
        IPage<ProcessVo> pageModel=oaProcessService.findPending(pageParam);
        return Result.ok(pageModel);
    }
    @GetMapping("show/{id}")
    public Result show(@PathVariable Integer id){
        Map<String,Object> map=oaProcessService.show(id);

        return Result.ok(map);
    }
    @PostMapping("approve")
    public Result approve(@RequestBody ApprovalVo approvalVo){
        oaProcessService.approve(approvalVo);
        return Result.ok();
    }
    @GetMapping("findProcessed/{page}/{limit}")
    public Result findProcessed(@PathVariable Integer page,@PathVariable Integer limit){
        IPage<ProcessVo> pageParam=new Page<>(page,limit);
       IPage<ProcessVo> pageModel= oaProcessService.findProcessed(pageParam);
       return Result.ok(pageModel);
    }
    @GetMapping("findStarted/{page}/{limit}")
    public Result findStarted(@PathVariable Integer page,@PathVariable Integer limit){
        IPage<ProcessVo> pageParam=new Page<>(page,limit);
       IPage<ProcessVo> pageModel= oaProcessService.findStarted(pageParam);
       return Result.ok(pageModel);
    }
}
